package io.dy.main;

import io.dy.custom.MyQueue;
import io.dy.model.Hero;
import io.dy.util.Lambda;
import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * @author : dmj
 * @date: 2024/12/18 10:26 上午
 * @description:
 */
public class StreamGroup {


    List<Hero> list = Arrays.asList(
            new Hero("杨过",100),
            new Hero("小龙女",98),
            new Hero("金轮法王",98),
            new Hero("郭靖",97),
            new Hero("李莫愁",95),
            new Hero("黄蓉",95),
            new Hero("H",95),
            new Hero("黄药师",99),
            new Hero("老顽童",99),
            new Hero("一灯大师",99)
    );

    @Test
    public void group(){
//        Map<Integer, List<Hero>> collect = list.stream().collect(Collectors.groupingBy(o -> o.getName().length(), Collectors.toList()));
//        for (Map.Entry<Integer, List<Hero>> entry : collect.entrySet()) {
//            System.out.println(entry);
//        }

//        Map<Integer, List<Hero>> collect1 = list.stream()
//                .collect(Collectors.groupingBy(
//                        o -> o.getName().length(),
//                        ConcurrentHashMap::new,
//                        Collectors.toCollection(LinkedList::new)));
//        System.out.println(collect1);


        list.stream().sorted((o1,o2)-> o1.getStrength().compareTo(o2.getStrength()));



        MyQueue<Hero> collect1 = list.stream().collect(Lambda.top(Hero::getName, 2));
        System.out.println(collect1);
    }
}
